package com.ruoyi.project.deployedtrials.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.myexperiment.domain.DetailsDto;
import com.ruoyi.project.myexperiment.domain.MyExment;
import com.ruoyi.project.myexperiment.service.MyExmentService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("website/teacherexment")
public class DeployedtrialsController extends BaseController {

    private  String prefix="system/deployedtrials";

    @Autowired
    private MyExmentService myExmentService;

    @RequiresPermissions("website:myexment:view")
    @GetMapping()
    public  String myexment(){
        return  prefix + "/myexment";
    }

    /**
     *查询我的实验
     */
    @RequiresPermissions("website:myexment:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo selectExment(MyExment myExment)
    {
        startPage();
        myExment.setCreateId(getUserId());
        List<MyExment> list = myExmentService.selectExmentList(myExment);
        /*for (MyExment lists:list){
            if (lists.getClassAddress()!=null && lists.getOrderTime()!=null && lists.getSection()!=null){
                lists.setExperimentMessage(lists.getClassAddress().toString()+"-"+lists.getOrderTime().toString()+""+lists.getSection().toString());
            }
        }*/
        //System.err.println(list);
        return getDataTable(list);
    }

    @RequiresPermissions("website:kaikecheck:edit")
    @PostMapping("/cancelFabu")
    @ResponseBody
    public AjaxResult quxiaoFabu(int id){
        //System.err.println("id:"+id);
        long userId=getSysUser().getUserId();
        HashMap<String,Object> map=new HashMap<>();
        map.put("id",id);
        map.put("userId",userId);
        int a= myExmentService.quxiaoFabu(map);
        System.err.println(a);
        if(a==0){
            return toAjax(false);
        }else{
            return toAjax(true);
        }
    }
}
